package com.recipedb.recipedb.repository;

import com.recipedb.recipedb.entity.Step;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public interface StepRepository extends JpaRepository<Step, Long> {

    List<Step> findByRecipeId(Long recipeId);

    @Modifying
    @Transactional
    @Query("UPDATE Step s SET s.description = :description WHERE s.id = :id")
    void updateDescription(@Param("id") Long id, @Param("description") String description);

    @Modifying
    @Transactional
    @Query("UPDATE Step s SET s.stepOrder = :stepOrder WHERE s.id = :id")
    void updateStepOrder(@Param("id") Long id, @Param("stepOrder") Integer stepOrder);

    @Modifying
    @Transactional
    @Query("UPDATE Step s SET s.imagePath = :imagePath WHERE s.id = :id")
    void updateImagePath(@Param("id") Long id, @Param("imagePath") String imagePath);

    @Modifying
    @Transactional
    @Query("UPDATE Step s SET s.imagePath = null WHERE s.id = :id")
    void clearImagePath(@Param("id") Long id);
}
